
<template>
  <!-- 按钮控制模态框显示隐藏 -->
  <button @click="open = true">Open Modal</button>
  <!-- 模态框部分 -->
  <!-- 使用传送门组件包裹 模态框组件 -->
  <Teleport to="body">
    <div v-if="open" class="modal">
      <p>我是模态框!</p>
      <button @click="open = false">Close</button>
    </div>
  </Teleport>
</template>

<script>
export default {
  data() {
    return {
      open: false,
    };
  },
};
</script>


<style scoped>
.modal {
  position: fixed;
  z-index: 999;
  top: 20%;
  left: 50%;
  width: 300px;
  margin-left: -150px;
}
</style>